package com.liuwei.spring.cloud.common.utils.feishu.message;

import cn.hutool.core.text.StrPool;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.tuple.Pair;

import java.util.List;

/**
 * @author : TextMessage
 * @version V1.0
 * @date: 2023/5/24 6:09 下午
 * @Description: TODO
 */
@Data
public class TextMessage extends BaseFeishuMessage {

     @JsonProperty("msg_type")
     private String messageType = "text";

     private MessageContent content;

     @Data
     public static class MessageContent{
        private String text;
     }

     public static TextMessage buildTextMessage(String title, List<Pair<String,String>> lines){
         TextMessage message = new TextMessage();
         StringBuilder builder = new StringBuilder();
         builder.append(title);
         builder.append(StrPool.CRLF);

         CollectionUtils.emptyIfNull(lines).forEach(x->{
             builder.append(x.getLeft());
             builder.append(x.getRight());
             builder.append(StrPool.CRLF);
         });

         MessageContent content = new MessageContent();
         content.setText(builder.toString());
         message.setContent(content);
         return message;
     }

}
